const { MongoClient } = require('mongodb');  
const url = 'mongodb://mongoAdmin:123456@web.anzhitek.com:27017/';   
const dbName = 'sensor';   
const collectionName = 'class';  
async function run(query) {  
    let client;  
    try {  
        client = await MongoClient.connect(url);  
        console.log("Connected successfully to server");    
        const db = client.db(dbName);  
        const collection = db.collection(collectionName);   
        const documents = await collection.find(query).toArray();  
        console.log(documents); // 处理查询结果
        return  documents 

    } catch (err) {  
        console.error(err);  
    } finally {  
        // 关闭数据库连接  
        await client?.close();  
    }  
}  
module.exports = {  
    run:run
}
  